#!/bin/bash

# Get build functions
. ./build_functions.sh

HERE=`pwd`
INSTALL_ROOT=/home/y01/bjoo/Devel/SciDAC/install
PRECISION=double
HOST_SYS=powerpc-bgl-blrts-gnu
BUILD_SYS=none
QMP_SRCDIR=${HERE}/qmp
QMP_INSTALLDIR=${INSTALL_ROOT}/qmp
BAGEL_INSTALL_DIR=${INSTALL_ROOT}/bagel
BAGEL_CPU=ppc440
BAGEL_ALLOC=malloc
BAGEL_COMM=qmp
BAGEL_WILSON_DIR=${INSTALL_ROOT}/bagel_${PRECISION}_${BAGEL_CPU}_${BAGEL_ALLOC}_${BAGEL_COMM}
LIBXML_SRCDIR=${HERE}/libxml2-2.6.6
LIBXML=${INSTALL_ROOT}/libxml-2.6.6
QDP_PARALLEL_ARCH=parscalar
QDP_DO_EDRAM=no
QDP_DO_BLAS=yes
CHROMA_DO_PAB_DSLASH=yes

# Munge directory names
QDP_INSTALLDIR=${INSTALL_ROOT}/qdp_${PRECISION}
if test "X${QDP_DO_EDRAM}X" == "XyesX";
then
	QDP_INSTALLDIR=${QDP_INSTALLDIR}_edram;
else
	QDP_INSTALLDIR=${QDP_INSTALLDIR}_ddr;
fi

if test "X${QDP_DO_BAGEL}X" == "XyesX";
then 
	QDP_INSTALLDIR=${QDP_INSTALLDIR}_blas;
fi

CHROMA_INSTALLDIR=${INSTALL_ROOT}/chroma_${PRECISION}
if test "X${QDP_DO_EDRAM}X" == "XyesX";
then
        CHROMA_INSTALLDIR=${CHROMA_INSTALLDIR}_edram;
else
        CHROMA_INSTALLDIR=${CHROMA_INSTALLDIR}_ddr;
fi
                                                                             
if test "X${CHROMA_DO_PAB_DSLASH}X" == "XyesX";
then
        CHROMA_INSTALLDIR=${CHROMA_INSTALLDIR}_pab_dslash;
fi

##
## The actual building is done here
##
##
## Build QMP
build_qmp ${QMP_SRCDIR} ${QMP_INSTALLDIR}

## Build LIBXML
build_libxml ${LIBXML_SRCDIR} ${LIBXML} ${HOST_SYS} ${BUILD_SYS}

## Build BAGEL
build_bagel ${HERE}/bagel ${BAGEL_INSTALL_DIR}

## Build Wilson Dslash
build_bagel_wilson_dslash ${HERE}/bagel_wilson_dslash \
                          ${BAGEL_WILSON_DIR} \
 		          ${BAGEL_INSTALL_DIR} \
	                  ${PRECISION} ${BAGEL_COMM} ${BAGEL_ALLOC} \
	                  ${BAGEL_CPU} ${HOST_SYS} ${BUILD_SYS} ${QMP_INSTALLDIR}


## Build QDP++
build_qdp  "${HERE}/qdp++" ${QDP_INSTALLDIR} ${QMP_INSTALLDIR} ${LIBXML} ${PRECISION} ${QDP_DO_EDRAM} ${QDP_DO_BLAS} ${HOST_SYS} ${BUILD_SYS} ${BAGEL_WILSON_DIR}

## Build Chroma
build_chroma ${HERE}/chroma ${CHROMA_INSTALLDIR} ${QDP_INSTALLDIR} ${HOST_SYS} ${BUILD_SYS} ${CHROMA_DO_PAB_DSLASH}
